package com.minelx.parallel;

import java.util.ArrayList;
import java.util.List;

import static java.util.stream.Collectors.toList;

public class EnrichedList {
	private final List<Integer> sources;

	public EnrichedList(List<Integer> sources) {
		this.sources = new ArrayList<>(sources);
	}

	public List<Integer> differencesWith(EnrichedList another) {
		List<Integer> notExistsInAnother = another.removeAll(this);
		return another.concat(notExistsInAnother);
	}

	public List<Integer> removeAll(EnrichedList removed) {
		return removed.sources.stream()
				.filter(removedSource -> !remove(removedSource))
				.collect(toList());
	}

	public List<Integer> concat(List<Integer> concatenated) {
		concatenated.addAll(sources);
		return concatenated;
	}

	public boolean remove(Integer source) {
		return sources.remove(source);
	}
}
